{% import "components/problem.html" as problem with context %}
{% extends "layout/basic.html" %}
{% block content %}
{% if typeof(rdoc['status']) === 'number' and not rev %}
  {{ set(UiContext, 'socketUrl', "record-detail-conn?domainId=" + rdoc.domainId + "&rid=" + rdoc._id) }}
{% endif %}
<div class="row">
  <div class="medium-9 columns collapsed">
    {% if typeof(rdoc['status']) === 'number' %}
      {% include 'record_detail_status.html' %}
    {% endif %}
    {% if rdoc['code'] or rdoc.files.code %}
    <div class="section">
      <div class="section__header">
        <h1 class="section__title">{{ _('Code') }}</h1>
        <div class="section__tools">
          <a class="primary rounded button" href="?download=true">
            <span class="icon icon-download"></span>
            {% if rdoc.files.hack %}{{ _('Download Hack Input') }}{% else %}{{ _('Download') }}{% endif %}
          </a>
        </div>
      </div>
      <div class="section__body">
        <pre class="line-numbers"><code class="language-{{ model.setting.langs[rdoc.lang].highlight }}">{{ rdoc['code'] }}</code></pre>
      </div>
    </div>
    {% endif %}
  </div>
  <div class="medium-3 columns">
    <div class="section side">
      <div class="section__header">
        <h1 class="section__title">{{ _('Information') }}</h1>
      </div>
    {% if handler.user.hasPerm(perm.PERM_REJUDGE) and not rdoc.files.hack %}
      <div class="section__body no-padding">
        <ol class="menu">
          <li class="menu__item">
            <form method="post">
              <button type="submit" name="operation" value="rejudge" class="menu__link">
                <span class="icon icon-refresh"></span> {{ _('Rejudge') }}
              </button>
            </form>
          </li>
          <li class="menu__item">
            <form method="post">
              <button type="submit" name="operation" value="cancel" class="menu__link">
                <span class="icon icon-close"></span> {{ _('Cancel Score') }}
              </button>
            </form>
          </li>
        </ol>
      </div>
    {% endif %}
    {% if handler.user.hasPerm(perm.PERM_SUBMIT_PROBLEM) and pdoc.config.hackable and rdoc.status === STATUS.STATUS_ACCEPTED and rdoc.uid !== handler.user._id %}
      <div class="section__body no-padding">
        <ol class="menu">
          <li class="menu__item">
            <a class="menu__link" href="{{ url('problem_hack', pid=pdoc.pid|default(pdoc.docId), rid=rdoc._id, query={tid:rdoc.contest} if rdoc.contest else {}) }}">
              <span class="icon icon-debug"></span> {{ _('Hack') }}
            </a>
          </li>
        </ol>
      </div>
    {% endif %}
      <div class="section__body typo no-media">
        <dl class="large horizontal">
          <dt>{{ _('Submit By') }}</dt>
          <dd>{{ user.render_inline(udoc, modbadge=false) }}</dd>
          {% if rdoc.hackTarget %}
            <dt>{{ _('Hacked') }}</dt>
            <dd><a href="{{ url('record_detail', rid=rdoc.hackTarget) }}">{{ rdoc.hackTarget }}</a></dd>
          {% endif %}
          {% if pdoc %}
            <dt>{{ _('Problem') }}</dt>
            <dd>
              {{ problem.render_problem_title(pdoc, tdoc, show_tags=false, show_invisible_flag=false) }}
            </dd>
          {% endif %}
          {% if tdoc %}
            <dt>{{ _('Homework') if tdoc.rule == 'homework' else _('Contest') }}</dt>
            <dd>
              <a href="{{ url('homework_detail' if tdoc.rule == 'homework' else 'contest_detail', tid=tdoc.docId) }}">{{ tdoc.title }}</a>
            </dd>
          {% endif %}
          {% if pdoc.config.type != 'objective' %}
            <dt>{{ _('Language') }}</dt>
            <dd>{{ model.setting.langs[rdoc.lang].display }}</dd>
          {% endif %}
          {% if rdoc.code %}
            <dt>{{ _('Code Length') }}</dt>
            <dd>{{ size(rdoc.code|length) }}</dd>
          {% endif %}
          <dt>{{ _('Submit At') }}</dt>
          <dd>{{ datetimeSpan(rdoc._id, false)|safe }}</dd>
          {% if rdoc.judgeAt %}
            <dt>{{ _('Judged At') }}</dt>
            <dd>{{ datetimeSpan(rdoc.judgeAt, false)|safe }}</dd>
          {% endif %}
          {% if judge_udoc %}
            <dt>{{ _('Judged By') }}</dt>
            <dd>{{ user.render_inline(judge_udoc, badge=false) }}</dd>
          {% endif %}
        </dl>
        {% if typeof(rdoc['status']) === 'number' %}
          {% include 'record_detail_summary.html' %}
        {% endif %}
      </div>
    </div>
    {% if allRevs|length %}
      <div class="section side">
        <div class="section__header">
          <h1 class="section__title">{{ _('History') }}</h1>
        </div>
        <div class="section__body no-padding">
          <ol class="menu">
            <li class="menu__item">
              <a href="?rev=" {% if not rev %}style="border-color: #4690d0;"{% endif %} class="menu__link">
                {{ _('Latest Version') }}
              </a>
            </li>
            {% for r, rtime in allRevs %}
            <li class="menu__item">
              <a href="?rev={{ r }}" {% if rev and rev.equals(r) %}style="border-color: #4690d0;"{% endif %} class="menu__link">
                {{ datetimeSpan(rtime, false)|safe }}
              </a>
            </li>
            {% endfor %}
          </ol>
        </div>
      </div>
    {% endif %}
  </div>
</div>
{% endblock %}
